package com.example.controller;

import com.example.DTO.UserReadingStatDTO;
import com.example.pojo.Result;
import com.example.pojo.UserReadingStat;
import com.example.service.StatService;
import com.example.utils.ThreadLocalUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value ="/statistics")
public class StatisticController {


    @Autowired
    private StatService statService;

    //用户个性化分析
    //用户阅读那种文章，让阅读时长+1
    @RequestMapping(value = "/addlove")
    public Result addLove(@RequestParam("articleId") Integer articleId){
        statService.addLove(articleId);
        return Result.success();
    }

    //获取用户阅读数据
    @RequestMapping(value = "/getUserReadingStat")
    public Result getUserReadingStat(){
        Claims claims = ThreadLocalUtil.get();
        Integer userid = (Integer) claims.get("id");
        List<UserReadingStatDTO> list = statService.getUserReadingStat(userid);
        return Result.success(list);
    }




}
